package pers.cz.node;

public enum NodeTypeEnum {

    BUTTON("button", ButtonNode.class),
    START("start", StartNode.class),
    CLICK("click", ClickNode.class),
    DBCLICK("dbClick", DbClickNode.class),
    IF("if", JudgeNode.class),
    TEXT("text", TextNode.class),
    ALERT("alert", AlertHandleNode.class),
    SWITCH("switch", SwitchNode.class),
    PRINT("print", PrintNode.class),
    OVER("over", OverNode.class),
    DELAYED("delayed", DelayedNode.class);

    private final String nodeName;
    private final Class<? extends Node> nodeClass;

    NodeTypeEnum(String nodeName, Class<? extends Node> nodeClass) {

        this.nodeName = nodeName;
        this.nodeClass = nodeClass;
    }

    public String getNodeName() {
        return nodeName;
    }

    public Class<? extends Node> getNodeClass() {
        return nodeClass;
    }

    public static Class<? extends Node> getNodeClassByNodeName(String nodeName) {

        NodeTypeEnum nodeTypeEnum = getEnumByNodeName(nodeName);

        return nodeTypeEnum.getNodeClass();
    }

    public static Class<? extends Node> getNodeClassByNode(Node node) {

        String nodeName = node.getName();

        return getNodeClassByNodeName(nodeName);
    }

    public static NodeTypeEnum getEnumByNodeName(String nodeName) {
        for (NodeTypeEnum anEnum : values()) {
            if (anEnum.getNodeName().equals(nodeName)) {
                return anEnum;
            }
        }
        return null;
    }


}
